#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
kill -12 PID: make the klog to reload /tmp/.rtcfg.<PID> file.
"""


import os
import signal

from mie.xlogger.klog import klog


def _sighandler(sig, frame):
    path = "/tmp/.rtcfg.%d" % os.getpid()
    try:
        with open(path, "rt") as f:
            for l in f.readlines():
                klog.rule_add_line(l.strip())
    except:
        pass

    finally:
        try:
            os.remove(path)
        except:
            pass


signal.signal(signal.SIGUSR2, _sighandler)
